package xuhaijia.lanou3g.autohome.myself;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import xuhaijia.lanou3g.autohome.R;

/**
 * Created by 7 on 16/8/31.
 */
public class HistoryAdapter extends BaseAdapter {
    Context context;
    ArrayList<History> history;

    public HistoryAdapter(Context context) {
        this.context = context;
    }

    public void setHistory(ArrayList<History> history) {
        this.history = history;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return history != null ? history.size() : 0 ;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_recsame , null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(history.get(position).getTitle());
        viewHolder.times.setText(history.get(position).getTimes());
        viewHolder.date.setText(history.get(position).getDate());
        Bitmap bitmap = BitmapFactory.decodeByteArray(history.get(position).getPicture() ,0 ,
                history.get(position).getPicture().length);
        viewHolder.iv.setImageBitmap(bitmap);
        return convertView;
    }

    private class ViewHolder {
        TextView title;
        TextView date;
        TextView times;
        ImageView iv;

        public ViewHolder(View view) {
            title = (TextView) view.findViewById(R.id.item_recsame_title);
            date = (TextView) view.findViewById(R.id.item_recsame_date);
            times = (TextView) view.findViewById(R.id.item_recsame_history);
            iv = (ImageView) view.findViewById(R.id.item_recsame_iv);
        }
    }
}
